#include "widget.h"
#include "ui_widget.h"
#include <QTableWidget>
#include <QDebug>
#include <QLabel>
#include <QString>
#include <QVBoxLayout>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    QLabel *label1 = new QLabel(ui->tab);
    label1->setText("标签页1");


    QLabel *label2 = new QLabel(ui->tab_2);
    label2->setText("标签页2");
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_add_clicked()
{
    int num = ui->tabWidget->count();
    qDebug() << num;

    QWidget *widget1 = new QWidget();
    ui->tabWidget->addTab(widget1, QString("标签页") + QString::number(num + 1));

    QVBoxLayout *layout = new QVBoxLayout(widget1);

    QLabel *label = new QLabel(widget1);
    label->resize(100,50);
    label->setText(QString("标签页") + QString::number(num + 1));
    layout->addWidget(label);


    ui->tabWidget->setCurrentIndex(num);
}

void Widget::on_pushButton_delete_clicked()
{
    int index = ui->tabWidget->currentIndex();
    ui->tabWidget->removeTab(index);
}
